<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="support.*, java.util.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Country of Citizenship</title>
</head>
<body>
	<h1>Country of Citizenship</h1>
	<!--assuming an existing jsp page -->
	<%
		String firstName = request.getParameter( "firstName" );
	    String lastName = request.getParameter( "lastName" );
	    String middleName = request.getParameter( "middleName" );
	    
	    student stu = (student)session.getAttribute("student");
	    
	    stu.setAttribute("firstName",firstName);
	    stu.setAttribute("lastName", lastName);
	    stu.setAttribute("middleName",middleName);
	    
	    session.setAttribute("student", stu);
	%>
	<h2><%= firstName + " " + middleName + " " + lastName%></h2>
	<br>
	
	<!-- Printing out all countries -->
	<h3>Countries:</h3>
	
  <% 
	   	support s = new support();   	
	   	
	   	String path1 = config.getServletContext().getRealPath("countries.txt");
	   	
	    //getCountries returns a vector of the countries to be used for choosing citizenship
	    Vector countries = s.getCountries(path1);
	   
	    int size = countries.size();
	    int incr = size/3;
	  	int size1 = 0;
	  	int size2 = size1 + incr;
	  	int size3 = size2 + incr;
	  	int size4 = size;
    %>
   
    
	<table border="1">
			<td>
				<%
				    //print all the countries
				    for(int i=size1; i<size2; i++){
				    	String country = (String)countries.get(i);
				    	out.println("<a href=\'residence.jsp?citizenship=" + country + "\'>" + country + "</a><br>");
				    }
				%>
			</td>
			<td>
				<%
				    //print all the countries
				    for(int i=size2; i<size3; i++){
				    	String country = (String)countries.get(i);
				    	out.println("<a href=\'residence.jsp?citizenship=" + country + "\'>" + country + "</a><br>");
				    }
				%>
			
			</td>
			<td>
				<%
				    //print all the countries
				    for(int i=size3; i<size4; i++){
				    	String country = (String)countries.get(i);
				    	out.println("<a href=\'residence.jsp?citizenship=" + country + "\'>" + country + "</a><br>");
				    }
				%>
			</td>
	</table>
   
</body>
</html>